<template>
  <div id="app" :style="scaleStyle">
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: "App",
  components: {},
  computed: {
    scaleStyle() {
      return {
        transform: `scale(${this.scale})`,
        transformOrigin: "top left",
      };
    },
  },
  methods: {
    scaleToFit() {
      const designWidth = 3840; // 设计稿宽度
      const designHeight = 1080; // 设计稿高度

      const screenWidth = window.innerWidth;
      const screenHeight = window.innerHeight;

      // 计算宽高比
      const scaleX = screenWidth / designWidth;
      const scaleY = screenHeight / designHeight;
      // 取较小的比例值，保证内容不会超出屏幕
      this.scale = Math.min(scaleX, scaleY);
    },
  },
  mounted() {
    // 初始化时调用
    this.scaleToFit();
    // 监听窗口大小变化
    window.addEventListener("resize", this.scaleToFit);
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
}
body {
  margin: 0px;
  /* font-size: calc(12px + 0.3vw); */
}
</style>
